#pragma once

#include <QObject>

namespace kryptos { namespace util {
  class Worker;
}}

namespace kryptos { namespace actions {


class Action : public QObject
{
    Q_OBJECT
public:
    Action();
    virtual ~Action();

    void         execute();
    virtual void cancel();

signals:
    void actionStarted   ();
    void actionProgress  (int progress);
    void actionError     (const QString& errorDesc);
    void actionEnded     (bool succeeded);
    void confirmAction   (const QString&, bool*);
    void getInputFromUser(const QString&, QString*);

                               //       Message  , Answer   , Result
    void getInputPasswordFromUser(const QString &, QString *, int *);
    void showMessageFile         (const QString &, const QString &, int *);

public slots:
    void Go();

protected:
    virtual bool Prepare  () = 0;
    virtual void RunAction() = 0;
    virtual bool Cleanup  () = 0;
    virtual void AddAndEmitProgress(int delta);
    virtual void SetAndEmitProgress(int absolute);

protected:
    QScopedPointer<kryptos::util::Worker> _worker;
    int     _actionProgress;
    bool    _cancelAction;
    bool    _actionSucceeded;
};

}}
